/**
 * 更多共同的列
 */
import React, {Component} from 'react';
import {View, StyleSheet, Text, Image, TouchableOpacity, Platform, Switch} from  'react-native';
let RightArrow = require('../../img/icon_cell_rightarrow.png');
export default class MoreCommonCell extends Component {
    constructor(props) {
        super(props);
        this.state = {
            isOn: false
        };
    }

    render() {
        return (
            <TouchableOpacity onPress={()=>this.scan()}>
                <View style={styles.container}>
                    <Text style={{marginLeft:5}}>{this.props.title}</Text>
                    {this.renderRightView()}
                </View>
            </TouchableOpacity>
        )
    }

    renderRightView() {
        if (this.props.isSwitch) {
            return (
                <Switch style={{marginRight:5}} value={this.state.isOn==true}
                        onValueChange={()=>{this.setState({isOn:!this.state.isOn})}}
                />
            )
        }
        else {
            return (
                <View style={{flexDirection:'row',alignItems:'center'}}>
                    {this.renderRightTitle()}
                    <Image source={RightArrow} style={{width:8,height:13,marginRight:5}}/>
                </View>
            )
        }
    }

    renderRightTitle() {
        if (this.props.rightTitle.length > 0) {
            return (
                <Text style={{color:'gray',marginRight:3}}>{this.props.rightTitle}</Text>
            )
        }
    }

    scan() {
        if (this.props.func==null){
            return
        }
        this.props.func();
    }
}


MoreCommonCell.propTypes = {
    title: React.PropTypes.string,
    isSwitch: React.PropTypes.bool,
    rightTitle: React.PropTypes.string,
    func:React.PropTypes.func
};
MoreCommonCell.defaultProps = {
    title: '',
    isSwitch: false,
    rightTitle: '',
    func:null
};
const styles = StyleSheet.create({
    container: {
        height: Platform.OS == 'ios' ? 40 : 36,
        backgroundColor: 'white',
        borderBottomColor: '#888888',
        borderBottomWidth: 0.5,
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center'
    }
});
